﻿
namespace Win.DataServices.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using Win.DataServices.Web.Model;


    // Implements application logic using the SLCCEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class AppDataService : LinqToEntitiesDomainService<SLCCEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'People' query.
        public IQueryable<Person> GetPeople()
        {
            return this.ObjectContext.People;
        }

        public void InsertPerson(Person person)
        {
            if ((person.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(person, EntityState.Added);
            }
            else
            {
                this.ObjectContext.People.AddObject(person);
            }
        }

        public void UpdatePerson(Person currentPerson)
        {
            this.ObjectContext.People.AttachAsModified(currentPerson, this.ChangeSet.GetOriginal(currentPerson));
        }

        public void DeletePerson(Person person)
        {
            if ((person.EntityState == EntityState.Detached))
            {
                this.ObjectContext.People.Attach(person);
            }
            this.ObjectContext.People.DeleteObject(person);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'PersonRoles' query.
        public IQueryable<PersonRole> GetPersonRoles()
        {
            return this.ObjectContext.PersonRoles;
        }

        public void InsertPersonRole(PersonRole personRole)
        {
            if ((personRole.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(personRole, EntityState.Added);
            }
            else
            {
                this.ObjectContext.PersonRoles.AddObject(personRole);
            }
        }

        public void UpdatePersonRole(PersonRole currentPersonRole)
        {
            this.ObjectContext.PersonRoles.AttachAsModified(currentPersonRole, this.ChangeSet.GetOriginal(currentPersonRole));
        }

        public void DeletePersonRole(PersonRole personRole)
        {
            if ((personRole.EntityState == EntityState.Detached))
            {
                this.ObjectContext.PersonRoles.Attach(personRole);
            }
            this.ObjectContext.PersonRoles.DeleteObject(personRole);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'RoleTypes' query.
        public IQueryable<RoleType> GetRoleTypes()
        {
            return this.ObjectContext.RoleTypes;
        }

        public void InsertRoleType(RoleType roleType)
        {
            if ((roleType.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(roleType, EntityState.Added);
            }
            else
            {
                this.ObjectContext.RoleTypes.AddObject(roleType);
            }
        }

        public void UpdateRoleType(RoleType currentRoleType)
        {
            this.ObjectContext.RoleTypes.AttachAsModified(currentRoleType, this.ChangeSet.GetOriginal(currentRoleType));
        }

        public void DeleteRoleType(RoleType roleType)
        {
            if ((roleType.EntityState == EntityState.Detached))
            {
                this.ObjectContext.RoleTypes.Attach(roleType);
            }
            this.ObjectContext.RoleTypes.DeleteObject(roleType);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'Sessions' query.
        public IQueryable<Session> GetSessions()
        {
            return this.ObjectContext.Sessions;
        }

        public void InsertSession(Session session)
        {
            if ((session.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(session, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Sessions.AddObject(session);
            }
        }

        public void UpdateSession(Session currentSession)
        {
            this.ObjectContext.Sessions.AttachAsModified(currentSession, this.ChangeSet.GetOriginal(currentSession));
        }

        public void DeleteSession(Session session)
        {
            if ((session.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Sessions.Attach(session);
            }
            this.ObjectContext.Sessions.DeleteObject(session);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'SpeakerSessions' query.
        public IQueryable<SpeakerSession> GetSpeakerSessions()
        {
            return this.ObjectContext.SpeakerSessions;
        }

        public void InsertSpeakerSession(SpeakerSession speakerSession)
        {
            if ((speakerSession.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(speakerSession, EntityState.Added);
            }
            else
            {
                this.ObjectContext.SpeakerSessions.AddObject(speakerSession);
            }
        }

        public void UpdateSpeakerSession(SpeakerSession currentSpeakerSession)
        {
            this.ObjectContext.SpeakerSessions.AttachAsModified(currentSpeakerSession, this.ChangeSet.GetOriginal(currentSpeakerSession));
        }

        public void DeleteSpeakerSession(SpeakerSession speakerSession)
        {
            if ((speakerSession.EntityState == EntityState.Detached))
            {
                this.ObjectContext.SpeakerSessions.Attach(speakerSession);
            }
            this.ObjectContext.SpeakerSessions.DeleteObject(speakerSession);
        }
    }
}


